package com.itheima.dao.impl;

import com.itheima.dao.ProdectDao;
import com.itheima.pojo.Prodect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository("prodectDao")
public class ProdectDaoImpl implements ProdectDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    /**
     * 查询功能
     * @return
     */
    public List<Prodect> findAll() {
        String sql = "select * from product";
        List<Prodect> prodectList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<Prodect>(Prodect.class));
        return prodectList;
    }

    public void addProduct() {
        String sql = "insert into product values(null,?,?)";
        jdbcTemplate.update(sql, "手机16", 1000);
    }

    public void deleteProduct() {
        String sql = "delete from product where id = ?";
        jdbcTemplate.update(sql, 16);
    }

    public void updataProduct() {
        String sql = "update product set name = ?,price = ? where id = ?";
        jdbcTemplate.update(sql,"手机20",1200,16);
    }

}
